<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Module source code &mdash; Dragonfly-modules v0.1 documentation</title>
    <link rel="stylesheet" href="_static/default.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '',
        VERSION:     '0.1',
        COLLAPSE_MODINDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="index" title="Index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" />
    <link rel="top" title="Dragonfly-modules v0.1 documentation" href="index.html" />
    <link rel="prev" title="Module source code" href="mod-notepad_example.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="mod-notepad_example.html" title="Module source code"
             accesskey="P">previous</a> |</li>
        <li><a href="index.html">Dragonfly-modules v0.1 documentation</a> &raquo;</li> 
      </ul>
    </div>  
    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  
  <div class="section" id="module-source-code">
<h1>Module source code<a class="headerlink" href="#module-source-code" title="Permalink to this headline">¶</a></h1>
<p>The most current version of this module can be downloaded from the <a class="reference external" href="http://dragonfly-modules.googlecode.com/svn/trunk/command-modules/_mousehold.py">repository here</a>.</p>
<div class="highlight-python"><table class="highlighttable"><tr><td class="linenos"><pre> 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73</pre></td><td class="code"><div class="highlight"><pre><span class="c">#</span>
<span class="c"># This file is a command-module for Dragonfly.</span>
<span class="c"># (c) Copyright 2008 by Christo Butcher</span>
<span class="c"># Licensed under the LGPL, see &lt;http://www.gnu.org/licenses/&gt;</span>
<span class="c">#</span>


<span class="kn">import</span> <span class="nn">pkg_resources</span>
<span class="n">pkg_resources</span><span class="o">.</span><span class="n">require</span><span class="p">(</span><span class="s">&quot;dragonfly &gt;= 0.6.5beta1.dev-r76&quot;</span><span class="p">)</span>

<span class="kn">import</span> <span class="nn">win32con</span>
<span class="kn">from</span> <span class="nn">ctypes</span>    <span class="kn">import</span> <span class="p">(</span><span class="n">pointer</span><span class="p">,</span> <span class="n">c_ulong</span><span class="p">)</span>
<span class="kn">from</span> <span class="nn">dragonfly</span> <span class="kn">import</span> <span class="p">(</span><span class="n">Grammar</span><span class="p">,</span> <span class="n">CompoundRule</span><span class="p">,</span> <span class="n">Choice</span><span class="p">,</span>
                       <span class="n">Config</span><span class="p">,</span> <span class="n">Section</span><span class="p">,</span> <span class="n">Item</span><span class="p">)</span>
<span class="kn">import</span> <span class="nn">dragonfly.actions.sendinput</span> <span class="kn">as</span> <span class="nn">sendinput</span>


<span class="c">#---------------------------------------------------------------------------</span>
<span class="c"># Create the main command rule.</span>

<span class="k">class</span> <span class="nc">CommandRule</span><span class="p">(</span><span class="n">CompoundRule</span><span class="p">):</span>

    <span class="n">spec</span>     <span class="o">=</span> <span class="s">&quot;[&lt;button&gt;] mouse &lt;updown&gt;&quot;</span>
    <span class="n">updown</span>   <span class="o">=</span> <span class="p">{</span>
                <span class="s">&quot;down&quot;</span><span class="p">:</span>   <span class="mf">0</span><span class="p">,</span>
                <span class="s">&quot;up&quot;</span><span class="p">:</span>     <span class="mf">1</span><span class="p">,</span>
               <span class="p">}</span>
    <span class="n">buttons</span>  <span class="o">=</span> <span class="p">{</span>
                <span class="s">&quot;left&quot;</span><span class="p">:</span>   <span class="mf">0</span><span class="p">,</span>
                <span class="s">&quot;middle&quot;</span><span class="p">:</span> <span class="mf">1</span><span class="p">,</span>
                <span class="s">&quot;right&quot;</span><span class="p">:</span>  <span class="mf">2</span><span class="p">,</span>
               <span class="p">}</span>
    <span class="n">extras</span>   <span class="o">=</span> <span class="p">[</span>
                <span class="n">Choice</span><span class="p">(</span><span class="s">&quot;button&quot;</span><span class="p">,</span> <span class="n">buttons</span><span class="p">),</span>
                <span class="n">Choice</span><span class="p">(</span><span class="s">&quot;updown&quot;</span><span class="p">,</span> <span class="n">updown</span><span class="p">),</span>
               <span class="p">]</span>

    <span class="n">flag_map</span> <span class="o">=</span> <span class="p">{</span>
                <span class="p">(</span><span class="mf">0</span><span class="p">,</span><span class="mf">0</span><span class="p">):</span> <span class="n">win32con</span><span class="o">.</span><span class="n">MOUSEEVENTF_LEFTDOWN</span><span class="p">,</span>
                <span class="p">(</span><span class="mf">0</span><span class="p">,</span><span class="mf">1</span><span class="p">):</span> <span class="n">win32con</span><span class="o">.</span><span class="n">MOUSEEVENTF_LEFTUP</span><span class="p">,</span>
                <span class="p">(</span><span class="mf">1</span><span class="p">,</span><span class="mf">0</span><span class="p">):</span> <span class="n">win32con</span><span class="o">.</span><span class="n">MOUSEEVENTF_MIDDLEDOWN</span><span class="p">,</span>
                <span class="p">(</span><span class="mf">1</span><span class="p">,</span><span class="mf">1</span><span class="p">):</span> <span class="n">win32con</span><span class="o">.</span><span class="n">MOUSEEVENTF_MIDDLEUP</span><span class="p">,</span>
                <span class="p">(</span><span class="mf">2</span><span class="p">,</span><span class="mf">0</span><span class="p">):</span> <span class="n">win32con</span><span class="o">.</span><span class="n">MOUSEEVENTF_RIGHTDOWN</span><span class="p">,</span>
                <span class="p">(</span><span class="mf">2</span><span class="p">,</span><span class="mf">1</span><span class="p">):</span> <span class="n">win32con</span><span class="o">.</span><span class="n">MOUSEEVENTF_RIGHTUP</span><span class="p">,</span>
               <span class="p">}</span>

    <span class="k">def</span> <span class="nf">_process_recognition</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">node</span><span class="p">,</span> <span class="n">extras</span><span class="p">):</span>
        <span class="n">updown</span> <span class="o">=</span> <span class="n">extras</span><span class="p">[</span><span class="s">&quot;updown&quot;</span><span class="p">]</span>
        <span class="k">if</span> <span class="s">&quot;button&quot;</span> <span class="ow">in</span> <span class="n">extras</span><span class="p">:</span>
            <span class="n">button</span> <span class="o">=</span> <span class="n">extras</span><span class="p">[</span><span class="s">&quot;button&quot;</span><span class="p">]</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">button</span> <span class="o">=</span> <span class="mf">0</span>

        <span class="n">key</span> <span class="o">=</span> <span class="p">(</span><span class="n">button</span><span class="p">,</span> <span class="n">updown</span><span class="p">)</span>
        <span class="n">flags</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">flag_map</span><span class="p">[</span><span class="n">key</span><span class="p">]</span>

        <span class="nb">input</span> <span class="o">=</span> <span class="n">sendinput</span><span class="o">.</span><span class="n">MouseInput</span><span class="p">(</span><span class="mf">0</span><span class="p">,</span> <span class="mf">0</span><span class="p">,</span> <span class="mf">0</span><span class="p">,</span> <span class="n">flags</span><span class="p">,</span> <span class="mf">0</span><span class="p">,</span> <span class="n">pointer</span><span class="p">(</span><span class="n">c_ulong</span><span class="p">(</span><span class="mf">0</span><span class="p">)))</span>
        <span class="n">array</span> <span class="o">=</span> <span class="n">sendinput</span><span class="o">.</span><span class="n">make_input_array</span><span class="p">([</span><span class="nb">input</span><span class="p">])</span>
        <span class="n">sendinput</span><span class="o">.</span><span class="n">send_input_array</span><span class="p">(</span><span class="n">array</span><span class="p">)</span>


<span class="c">#---------------------------------------------------------------------------</span>
<span class="c"># Create and load this module&#39;s grammar.</span>

<span class="n">grammar</span> <span class="o">=</span> <span class="n">Grammar</span><span class="p">(</span><span class="s">&quot;mouse hold&quot;</span><span class="p">)</span>
<span class="n">grammar</span><span class="o">.</span><span class="n">add_rule</span><span class="p">(</span><span class="n">CommandRule</span><span class="p">())</span>
<span class="n">grammar</span><span class="o">.</span><span class="n">load</span><span class="p">()</span>

<span class="c"># Unload function which will be called by natlink at unload time.</span>
<span class="k">def</span> <span class="nf">unload</span><span class="p">():</span>
    <span class="k">global</span> <span class="n">grammar</span>
    <span class="k">if</span> <span class="n">grammar</span><span class="p">:</span> <span class="n">grammar</span><span class="o">.</span><span class="n">unload</span><span class="p">()</span>
    <span class="n">grammar</span> <span class="o">=</span> <span class="bp">None</span>
</pre></div>
</td></tr></table></div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <h4>Previous topic</h4>
            <p class="topless"><a href="mod-notepad_example.html" title="previous chapter">Module source code</a></p>
            <h3>This Page</h3>
            <ul class="this-page-menu">
              <li><a href="_sources/mod-_mousehold.txt">Show Source</a></li>
            </ul>
          <h3>Quick search</h3>
            <form class="search" action="search.html" method="get">
              <input type="text" name="q" size="18" /> <input type="submit" value="Go" />
              <input type="hidden" name="check_keywords" value="yes" />
              <input type="hidden" name="area" value="default" />
            </form>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="mod-notepad_example.html" title="Module source code"
             accesskey="P">previous</a> |</li>
        <li><a href="index.html">Dragonfly-modules v0.1 documentation</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
      &copy; Copyright 2008, Christo Butcher.
      Last updated on Apr 10, 2009.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.5.1.
    </div>
  </body>
</html>